package LC;

/**
 * @ClassName LC8
 * @Description: TODO
 * @Author hl
 * @Date 2020/8/2
 * @Version V1.0
 **/
public class LC8 {

    public static void main(String[] args) {
        System.out.println( myAtoi("-91283472332"));
    }


    public static  int myAtoi(String str) {
        if(str==null||str.length()==0){
            return 0;
        }
        str=str.trim();
        char[] arr=str.toCharArray();
        long num=0;
        int flag=1;
        int i=0;
        if(!Character.isDigit(arr[0])){
         if(arr[0]!='+'&&arr[0]!='-'){
             return  0;
         }
         if(arr[0]=='-'){
             flag=-1;
         }
         i++;
        }
        for(;i<arr.length;i++){
         if(Character.isDigit(arr[i])){
             num=num*10+(arr[i]-'0');
             if(flag==1&&num>=Integer.MAX_VALUE){
                 return Integer.MAX_VALUE;
             }
             if(flag==-1&&num>=Integer.MAX_VALUE){
                 return Integer.MIN_VALUE;
             }

         }else{
             break;
         }
        }
      return (int)num*flag;
    }
}
